[#import "/framework/JGP.htm"  as JGP]
<!--
项目   jgp-cloud-parent
作者   LOUFEI [Gavin]
时间   2019-09-03
-->
[@JGP.head "Title"/]
[@JGP.body]
    <jgp-div _row="['30','*']" _runit="px">
        <div slot="1-1">
            <div>
                <jgp-btn _fn="addForm">创建表单</jgp-btn>
            </div>
        </div>
        <jgp-div slot="2-1" _col="['40','*']">
            <jgp-div slot="1-1" _row="['85','*','85','*']" _runit="px">
                <jgp-query slot="1-1" _target="form-grid" _action="/form/formApiController/queryForm">
                    <jgp-form-group _title="表单">
                        <jgp-text _col="12" _name="name" _placeholder="表单名"></jgp-text>
                    </jgp-form-group>
                </jgp-query>
                <jgp-grid slot="2-1" _id="form-grid" _onclick="queryAttr"
                          _record_tools="[{'icon':'edit','tip':'修改','fn':'editForm'},
                          {'icon':'plus','tip':'添加属性','fn':'addAttr'},
                          {'icon':'sort','tip':'配置','fn':'configFormAttr'},
                          {'icon':'trash-o','tip':'删除','fn':'removeForm'}]">
                </jgp-grid>
                <jgp-query slot="3-1" _id="attr-query" _target="attr-grid">
                    <jgp-form-group _title="属性">
                        <jgp-text _col="12" _name="label" _placeholder="属性名"></jgp-text>
                    </jgp-form-group>
                </jgp-query>
                <jgp-grid slot="4-1" _id="attr-grid" slot="2-1" _cols="['100','80','80']" _c_max_width="100px"
                          _record_tools="[{'icon':'edit','tip':'修改','fn':'editFormAttr'},
                  {'icon':'trash-o','tip':'删除','fn':'removeFormAttr'}]">
                </jgp-grid>
            </jgp-div>
            <jgp-panel slot="1-2" _title="预览" _border="left" _id="review-panel" _url="javascript:void(0);" _default_tools="['max','refresh']">

            </jgp-panel>
        </jgp-div>
    </jgp-div>
[/@JGP.body]

[@JGP.foot]
    <script>
        function addForm() {
            var dialog = {
                'title': '添加表单',
                'width': '500px',
                'height': '470px',
                'url': '/form/formController/addForm',
                'callback': function (result) {
                    if(result){
                        location.reload();
                    }
                }
            };
            JGP.$dialog(dialog);
        }

        function editForm(args) {
            var formId = args.back.record.id;
            var dialog = {
                'title': '修改表单',
                'width': '500px',
                'height': '470px',
                'url': '/form/formController/editForm/'+formId,
                'callback': function (result) {
                    if(result){
                        location.reload();
                    }
                }
            };
            JGP.$dialog(dialog);
        }

        function removeForm(args) {
            var formId = args.back.record.id;
            JGP.$confirm('是否删除:'+args.back.record.name,function () {
                JGP.$post('/form/formApiController/removeForm/'+formId,{},function (result) {
                    if(result.flag){
                        location.reload();
                    }else{
                        JGP.$error('无法删除'+args.back.record.name);
                    }
                })
            })
        }

        function addAttr(args) {
            var dialog = {
                'title': '添加表单属性',
                'width': '500px',
                'height': '600px',
                'url': '/form/formController/addFormAttr/'+args.back.record.id,
                'callback': function (result) {
                    if(result){
                        JGP.query('attr-query').searchTo();
                        JGP.panel('review-panel').refresh();
                    }
                }
            };
            JGP.$dialog(dialog);
        }

        function editFormAttr(args) {
            var attrId = args.back.record.id;
            var dialog = {
                'title': '修改属性',
                'width': '500px',
                'height': '600px',
                'url': '/form/formController/editFormAttr/'+attrId,
                'callback': function (result) {
                    if(result){
                        JGP.query('attr-query').searchTo();
                        JGP.panel('review-panel').refresh();
                    }
                }
            };
            JGP.$dialog(dialog);
        }

        function removeFormAttr(args) {
            var formId = args.back.record.id;
            JGP.$confirm('是否删除:'+args.back.record.label,function () {
                JGP.$post('/form/formApiController/removeFormAttr/'+formId,{},function (result) {
                    if(result.flag){
                        location.reload();
                    }else{
                        JGP.$error('无法删除'+args.back.record.name);
                    }
                })
            })
        }


        function queryAttr(args) {
            var attrUrl="/form/formApiController/queryFormAttr/"+args.back.record.id;
            var reviewUrl="/form/formController/review/"+args.back.record.id;
            JGP.query('attr-query').searchTo(attrUrl);
            JGP.panel('review-panel').load(reviewUrl);
        }

        function configFormAttr(args) {
            var dialog = {
                'title': '配置',
                'width': '300px',
                'height': '500px',
                'url': "/form/formController/configFormAttr/"+args.back.record.id,
                'callback': function (result) {
                    if(result){
                        JGP.query('attr-query').search();
                        JGP.panel('review-panel').refresh();
                    }
                }
            };
            JGP.$dialog(dialog);
        }
    </script>
[/@JGP.foot]